package com.gjw.planeWar;

import utils.RandomUtil;

/**
 * @author gjw19
 * @date 2019/5/2
 */
public class Props {
    private static final Props INSTANCE = new Props();

    private Props() {
    }

    public static Props getInstance() {
        return INSTANCE;
    }

    // 窗口常量
    static final int GAME_WIDTH = PropertyMgr.getInt("GAME_WIDTH");
    static final int GAME_HEIGHT = PropertyMgr.getInt("GAME_HEIGHT");

    // 关卡
    public static int LEVEL = PropertyMgr.getInt("LEVEL");
    // 改变方向的比较数
    public static int CHANGE_NUM = PropertyMgr.getInt("CHANGE_NUM");
    // 下落速度累加
    public static int DOWN_SPEED = PropertyMgr.getInt("DOWN_SPEED");
    // 分数
    public static int SCORE = 0;
    // 分数翻倍
    public static int SCORE_DOUBLE = 0;
    // 敌军飞机数
    public static int ENEMY_NUM = PropertyMgr.getInt("ENEMY_NUM");
    // 击落敌军数
    public static int SHOOT_ENEMY_NUM = 0;
    // 添加关卡的比较随机数
    public static int ADD_LEVEL_NUM = RandomUtil.randomNum(20, 40);
    // 上次升级关卡击落的飞机数
    public static int BEFORE_ADD_LEVEL_SHOOT_NUM = 1;
    // 添加生命的比较随机数
    public static int ADD_HP_NUM = RandomUtil.randomNum(66, 88);
    // 上次添加HP击落的飞机数
    public static int BEFORE_ADD_HP_SHOOT_NUM = 1;
    // 添加爆炸的比较随机数
    public static int ADD_EXPLODE_NUM = RandomUtil.randomNum(88, 100);
    // 上次添加爆炸击落的飞机数
    public static int BEFORE_ADD_EXPLODE_SHOOT_NUM = 1;

    // 敌军飞机生成随机数
    public static int ENEMY_PLANE_SIZE = RandomUtil.randomNum(0, 5);

    // 二级子弹击落敌机数
    public static int TWO_FIRE = PropertyMgr.getInt("TWO_FIRE");
    // 三级子弹击落敌机数
    public static int THREE_FIRE = PropertyMgr.getInt("THREE_FIRE");


    // 升级关卡
    public static void isAddLevel() {
        if (SHOOT_ENEMY_NUM % ADD_LEVEL_NUM == 0 && SHOOT_ENEMY_NUM != 0 && SHOOT_ENEMY_NUM != BEFORE_ADD_LEVEL_SHOOT_NUM) {
            BEFORE_ADD_LEVEL_SHOOT_NUM = SHOOT_ENEMY_NUM;
            LEVEL++;
            levelRule(LEVEL);
        }
    }


    // 是否添加爆炸
    public static boolean isAddExplode() {
        if (SHOOT_ENEMY_NUM % ADD_EXPLODE_NUM == 0 && SHOOT_ENEMY_NUM != 0 && SHOOT_ENEMY_NUM != BEFORE_ADD_EXPLODE_SHOOT_NUM) {
            BEFORE_ADD_EXPLODE_SHOOT_NUM = SHOOT_ENEMY_NUM;
            return true;
        }
        return false;
    }

    // 关卡规则
    public static void levelRule(int level) {
        switch (level) {
            case 2:
                ENEMY_NUM += 2;
                break;
            case 3:
                CHANGE_NUM--;
                EnemyPlane.HORIZONTAL_SPEED++;
                break;
            case 4:
                SCORE_DOUBLE++;
                CHANGE_NUM--;
                Props.DOWN_SPEED++;
                ENEMY_NUM++;
                ENEMY_PLANE_SIZE++;
                break;
            case 5:
                CHANGE_NUM--;
                EnemyPlane.HORIZONTAL_SPEED++;
                Props.DOWN_SPEED++;
                ENEMY_NUM++;
                break;
            case 6:
                ENEMY_NUM++;
                EnemyPlane.HORIZONTAL_SPEED += 2;
                CHANGE_NUM--;
                ENEMY_PLANE_SIZE++;
                break;
            case 7:
                ENEMY_NUM--;
                EnemyPlane.HORIZONTAL_SPEED++;
                CHANGE_NUM--;
                Props.DOWN_SPEED++;
                SCORE_DOUBLE++;
                break;
            case 8:
                ENEMY_NUM++;
                CHANGE_NUM--;
                Props.DOWN_SPEED += 2;
                break;
            case 9:
                CHANGE_NUM--;
                EnemyPlane.HORIZONTAL_SPEED++;
                ENEMY_PLANE_SIZE++;
                break;
            case 10:
                CHANGE_NUM--;
                EnemyPlane.HORIZONTAL_SPEED++;
                Props.DOWN_SPEED++;
                SCORE_DOUBLE++;
                break;
            default:
                ENEMY_NUM++;
                SCORE_DOUBLE++;
                ENEMY_PLANE_SIZE++;
                Props.DOWN_SPEED++;
        }
    }
}
